package com.example.myapplication.Style;

import android.os.Bundle;
import android.view.MenuItem;
import android.widget.ListView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import com.example.myapplication.ArrayAdapterInclude.IntentArrayListAdapter;
import com.example.myapplication.Person;
import com.example.myapplication.R;
import java.util.ArrayList;

public class PersonInfoActivity extends AppCompatActivity {
  ArrayList<Person> personArrayList;
  String title;
  @Override protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.intent_test_sublayout3);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle("xml解析");
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    GetData();
    ConvertText();
  }

  @Override public boolean onOptionsItemSelected(@NonNull MenuItem item) {
    switch (item.getItemId()) {
      case android.R.id.home:
        GoBack();
    }
    return true;
  }

  private void GoBack() {
    finish();
  }

  private void GetData() {
    personArrayList = (ArrayList<Person>) getIntent().getExtras().getSerializable("personList");
    title=getIntent().getStringExtra("title");
  }
  private void ConvertText() {
    if (personArrayList == null) {
      return;
    }
    getSupportActionBar().setTitle(title);
    IntentArrayListAdapter adapter = new IntentArrayListAdapter(this, personArrayList);
    ListView listView = (ListView) findViewById(R.id.infolist);
    listView.setAdapter(adapter);

  }
}
